package com.ljt.base.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.ljt.base.R;
import com.ljt.base.listener.OnDialogSelectListener;
import com.ljt.base.utils.LogUtil;
import com.ljt.base.wheel.WheelGenderPicker;

import java.util.ArrayList;
import java.util.List;

public class GenderDialog extends BaseDialog implements View.OnClickListener {

   private Context mContext;
   private OnDialogSelectListener listener;
   private WheelGenderPicker wheelGenderPicker;
   private TextView tvModuleCancel, tvModuleSubmit;
   private List<String> list;

   public GenderDialog(@NonNull Context context) {
      super(context);
      this.mContext = context;
   }

   public void setOnDialogSelectListener(OnDialogSelectListener listener) {
      this.listener = listener;
   }

   /**
    * 初始化界面
    *
    * @return
    */
   @Override
   public int intLayoutId() {
      return R.layout.dialog_gender_select;
   }

   /**
    * 逻辑处理方法
    *
    * @param holder
    * @param dialog
    */
   @Override
   public void convertView(ViewHolder holder, BaseDialog dialog) {
      wheelGenderPicker = holder.getView(R.id.wdPModule);
      list = new ArrayList<>();
      wheelGenderPicker.setItemTextColor(mContext.getResources().getColor(R.color.black));
      wheelGenderPicker.setItemTextSize(36);
      wheelGenderPicker.setAtmospheric(true);
      //设置弯曲
      wheelGenderPicker.setCurved(true);

      tvModuleCancel = holder.getView(R.id.tvModuleCancel);
      tvModuleSubmit = holder.getView(R.id.tvModuleSubmit);
      tvModuleCancel.setOnClickListener(this);
      tvModuleSubmit.setOnClickListener(this);
      setDimAmount(0.80f);
   }

   /**
    * 数据赋值
    * @param listStr
    */
   public void setListDate(List<String> listStr){
      list.clear();
      list.addAll(listStr);
      wheelGenderPicker.updateYears(list);
   }

   /**
    * 男女
    */
   private List<String> listAns = new ArrayList<>();
   public void setGenderList(){
      listAns.clear();
      listAns.add("男");
      listAns.add("女");
      setListDate(listAns);
   }

   /**
    * 身高
    */
   public void setHeightList(){
      listAns.clear();
      for(int i = 65;i < 300;i++){
         listAns.add(String.valueOf(i));
      }
      setListDate(listAns);
   }

   /**
    * 血型
    */
   public void setBloodTypeList(){
      listAns.clear();
      listAns.add("A");
      listAns.add("B");
      listAns.add("AB");
      listAns.add("O");
      setListDate(listAns);
   }

   /**
    * 体重
    */
   public void setWeightList(){
      listAns.clear();
      for(int i = 1;i < 400;i++){
         listAns.add(String.valueOf(i));
      }
      setListDate(listAns);
   }

   public void setTextRes(TextView tvModule, String str) {
      tvModule.setTextColor(mContext.getResources().getColor(R.color.black));
      tvModule.setText(str);
   }


   private String month, day;

   @SuppressLint("NotifyDataSetChanged")
   @Override
   public void onClick(View view) {
      int id = view.getId();
      if (id == R.id.tvModuleCancel) {
         dismiss();
      } else if (id == R.id.tvModuleSubmit) {
         LogUtil.INSTANCE.e("点击确定");
         if (listener != null) {
            listener.setOnDialogSelectListener(wheelGenderPicker.getCurrentResult());
         } else {
            dismiss();
         }
      }
   }
}

